package com.cloudwise.controller;



import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloudwise.entity.Dept;
import com.cloudwise.entity.EducationType;
import com.cloudwise.entity.ReturnBean;
import com.cloudwise.service.EducationTypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (EducationType)表控制层
 *
 * @author makejava
 * @since 2022-01-22 17:34:37
 */
@RestController
@RequestMapping("educationType")
public class EducationTypeController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private EducationTypeService educationTypeService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param educationType 查询实体
     * @return 所有数据
     */
    @GetMapping("selectAll")
    public ReturnBean selectAll(Integer limit, Integer page, EducationType educationType) {

        Page<EducationType> educationTypePage = new Page<>(page,limit);
        QueryWrapper<EducationType> queryWrapper = new QueryWrapper<>();
        if(ObjectUtil.isNotEmpty(educationType.getEducationType())){
            queryWrapper.like("education_type",educationType.getEducationType());
        }


        Page<EducationType> page1 = this.educationTypeService.page(educationTypePage,queryWrapper);
        return super.success(page1.getRecords(),page1.getTotal());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ReturnBean selectOne(@PathVariable Serializable id) {
        return success(this.educationTypeService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param educationType 实体对象
     * @return 新增结果
     */
    @PostMapping("insert")
    public ReturnBean insert(@RequestBody EducationType educationType) {
        boolean save = this.educationTypeService.save(educationType);
        if (save) {
            return super.success(educationType,1L);
        } else {
            return super.fail(educationType,1L);
        }
    }

    /**
     * 修改数据
     *
     * @param educationType 实体对象
     * @return 修改结果
     */
    @PutMapping("update")
    public ReturnBean update(@RequestBody EducationType educationType) {
        boolean update = this.educationTypeService.updateById(educationType);
        if (update) {
            return super.success(educationType,1L);
        } else {
            return super.fail(educationType,1L);
        }
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping("delete")
    public ReturnBean delete(@RequestParam(value = "idList[]",required = false) List<Long> idList) {
        return success(this.educationTypeService.removeByIds(idList));
    }
}

